import { createRouter, createWebHistory } from 'vue-router'


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // 设置根路由重定向到登录页面
    { path: '/', redirect: '/businessLogin' },

    // 登录页面路由
    {
      path: '/businessLogin',
      name: 'BusinessLogin',
      component: () => import("@/views/shop/BusinessLogin.vue"),
    },

    {
      // 一级路由

      path: '/home',
      name: 'home',
      component: () => import('../views/home/Layout.vue'),
      // 二级路由
      children: [
        {
          path: "/emp",
          component: () => import("@/views/emp/Employee.vue"),
        },
        //店铺分类
        {
          path: "/shopCategory",
          component: () => import("@/views/emp/ShopCategory.vue"),
        },
        //商家
        {
          path: "/businessList",
          component: () => import("@/views/shop/BusinessList.vue"),
        },
        //店铺状态
        {
          path: "/shopAuditList",
          component: () => import("@/views/emp/ShopAudit.vue"),
        },
        //店铺列表
        {
          path: "/shopList",
          component: () => import("@/views/shop/ShopList.vue"),
        },
        // 添加店铺
        {
          path: "/addShop",
          component: () => import("@/views/shop/AddShop.vue"),
        },
        // 添加菜品分类
        {
          path: "/foodCategory",
          component: () => import("@/views/food/FoodCategory.vue"),
        },

        // 菜品
        {
          path: "/food",
          component: () => import("@/views/food/Food.vue"),
        },


      ],
    },
    // 平台员工
    {
      path: "/empLogin",
      name: "empLogin",
      component: () => import("@/views/emp/EmpLogin.vue"),
    },
    // 商家注册
    {
      path: "/businessRegist",
      component: () => import("@/views/shop/BusinessRegist.vue"),
    },
    {
      path: "/businessLogin",
      component: () => import("@/views/shop/BusinessLogin.vue"),
    },
  ],
});

// // 添加一个路由前置守卫
// router.beforeEach(async (to, from) => {
//   // 本地存储中获取登录的用户信息
//   let info = localStorage.getItem("loginInfo");
//   if ( !info ) { 
//     if (to.path != "/businessLogin") {
//       if (to.path != "/empLogin") { return { path: "/businessLogin" } };
//     }
//   }
//   // 防止没有权限的用户访问某些路由地址
//   // let loginInfo = JSON.parse(info);
//   // if (!loginInfo.role && to.path == "/businessList") { 
//   // return { path: "/" }
//   // }
//  });
// 导出路由
export default router
